﻿/* 
 * author: www.cnblogs.com/luminji
 * date  : 2011/12/28
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Luminji.Exam.Infrastructure.Repositories.Papers;
using Luminji.Exam.Infrastructure.Repositories.Subjects;
using Luminji.Exam.Model.Subjects;
using Luminji.Exam.Model.Papers;
using Luminji.ExamWeb.Helpers;
using Luminji.ExamWeb.Helpers.Tools;
using Luminji.Exam.Model;
using Luminji.Infrastructure.UnitOfWork;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;

namespace Luminji.ExamWeb.Controllers
{
    public class SubjectController : BaseExamControl
    {
        private PaperService _paperService;
        private SubjectService _subjectService;

        public SubjectController()
        {
            IUnitOfWork uw = new UnitOfWork();
            _subjectService = new SubjectService(new SubjectRepository(uw), uw);
            _paperService = new PaperService(new PaperRepository(uw),uw);

        }
        
        public ActionResult Index(string subject, string code, int? pageNum)
        {
            var subjects = _subjectService.FindAllIntoThree();
            ViewBag.SubjectView = SubjectTool.GetSubjectHtmlView(subjects);

            ViewBag.SubjectName = subject;
            ViewBag.SubjectCode = code;
            ViewBag.PageNum = pageNum ?? 1;

            ViewBag.TotalPageNum = _paperService.GetPapersNumsBySubjectAndChildrenCode(code);
            ViewBag.PaperList = _paperService.GetPapersBySubjectAndChildrenCodeInPage(code, pageNum ?? 1);
            return View();
        }

    }
}
